<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"                  
                xmlns:f="http://java.sun.com/jsf/core"  
                xmlns:p="http://primefaces.org/ui"
                template="./default_template.xhtml">


    <ui:define name="content">
        <f:view>
            <h:form id="form" rendered="#{userController.utilisateur.typeUser == 'Admin'}">   
                <h1><h:outputText value="Tous les comptes :"/></h1>
                <p:dataTable var="item" value="#{compteMBean.modele}" paginator="true" rows="5"  
                            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"  
                            rowsPerPageTemplate="5,10,15" id="compteTable"
                            selectionMode="single"
                            selection="#{compteMBean.selectC}" 
                            lazy="true">  

                    <p:ajax event="rowSelect" listener="#{compteMBean.onRowSelect}" update=":form:display" oncomplete="compteDialog.show()" />  
                    
                    <p:column headerText="Id" sortBy="#{item.id}">  
                        <h:outputText value="#{item.id}" />  
                    </p:column> 
                    
                    <p:column headerText="Proprietaire">  
                        <h:outputText value="#{userController.getUserByCompte(item).nom}" />  
                    </p:column>  
                    
                    <p:column headerText="Type" sortBy="#{item.type.libelleType}">  
                        <h:outputText value="#{item.type.libelleType}" />  
                    </p:column>  

                    <p:column headerText="Solde" sortBy="#{item.solde}">  
                        <h:outputText value="#{item.solde}" />  
                    </p:column>
                </p:dataTable>  

                <p:dialog header="Détails du compte" widgetVar="compteDialog" resizable="false"  
                        showEffect="explode" hideEffect="explode">  
                    
                    <h4>Description</h4>
                    <h:panelGrid id="display" columns="2" cellpadding="4">
                        <h:outputText value="Propriétaire :" />  
                        <h:outputText value="#{userController.getUserByCompte(compteMBean.selectC).nom}" style="font-weight:bold"/>  
                        
                        <h:outputText value="Compte n° :" />  
                        <h:outputText value="#{compteMBean.selectC.id}" style="font-weight:bold"/>  
                        
                        <h:outputText value="Type Compte :" />  
                        <h:outputText value="#{compteMBean.selectC.type.libelleType}" style="font-weight:bold"/>  

                        <h:outputText value="Solde:" />  
                        <h:outputText value="#{compteMBean.selectC.solde} €" style="font-weight:bold"/>
                        <h4>Opérations</h4>
                        <p:dataTable value="#{compteMBean.selectC.operations}" var="item" rowStyleClass="#{item.montant lt 0 ? 'alert alert-error' : 'alert alert-success'}"
                                     emptyMessage="Aucune opérations.">
                            <p:column headerText="Date">
                                <h:outputText value="#{item.dateOperation}">
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>
                            <p:column headerText="Description"> 
                                <h:outputText value="#{item.description}"/> 
                            </p:column>  

                            <p:column headerText="Montant">
                                <h:outputText value="#{item.montant}"/>
                            </p:column>
                        </p:dataTable>
                    </h:panelGrid>
                </p:dialog>
            </h:form>  
        </f:view>
    </ui:define>

</ui:composition>
